<template>
<div>
  <p>用户名：<input type="text" v-model="form.username"></p>
  <p>密码：<input type="text" v-model="form.password"></p>
  <button @click="add">注册</button>
  <br>
  <br>
  <br>
  <h1 style="background-color: red">登录页面</h1>
  <p>用户名：<input type="text" v-model="ser.username"></p>
  <p>密码：<input type="text" v-model="ser.password"></p>
  <button @click="login">登录</button>
</div>
</template>

<script>
export default {
  name: "teacher",
  data(){
    return{
      form:{},
      ser:{},
    }
  },
  methods:{
    add(){
      this.$axios.post('users/teacher/',this.form)
      .then(res=>{
        if(res.data.code==200){
          alert('注册成功')
        }else {
          alert('注册失败')
        }
      })
    },
    login(){
      this.$axios.post('users/login/',this.ser)
      .then(res=>{
        if (res.data.code==200){
          localStorage.setItem('userid',res.data.userid)
          localStorage.setItem('username',res.data.username)
          alert('登陆成功')
          this.$router.push('student')
        }else {
          alert(meg)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
